<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*"%>
<%@page language="java" import="java.util.*"%>
<%
            String suid1 = (String) session.getAttribute("suid");
            String role = (String) session.getAttribute("role");
            String password1 = request.getParameter("confirm");

            Connection connection = null;
            try {

                String driverName = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);

                // Create a connection to the database
                String serverName = "10.0.0.27";
                String portNumber = "1521";
                String sid = "XE";
                String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
                String uname = "aranya27";
                String pword = "doodledo";

                connection = DriverManager.getConnection(url, uname, pword);



              // enter code here

                Statement st = null;
                out.println(role);
                st = connection.createStatement();
                if(role.equals("student")){
                    String str = "update aranya27.student_ranks set password ='"+password1+"'where suid=" + suid1;
                    st.executeUpdate(str);
                    session.setAttribute("message", "Password changed succesfully.");
                    response.sendRedirect("student/studentHome.jsp");
                }
                else if(role.equals("admin")){
                    String str = "update aranya27.admin_details set password ='"+password1+"'where eid=" + suid1;
                    st.executeUpdate(str);
                    session.setAttribute("message", "Password changed succesfully.");
                    response.sendRedirect("Admin/totalstudDetails.jsp");
                }
                connection.close();
                //end here
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                System.out.println(" Could not find the database driver");
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("Could not connect to the database");
            }



%>